package game.editer.ui;

import game.editer.view.SoundSelectView;
import hx.events.MouseEvent;

/**
 * 音频选择器
 */
class SoundInput extends BaseAttributeInput {
	var button = new Button();

	override function onInit() {
		super.onInit();
		button.text = "选择";
		button.width = 85;
		button.addEventListener(MouseEvent.CLICK, (e) -> {
			var view = new SoundSelectView("设置音频", 800, 600);
			this.topView.addChild(view);
			view.onSelected = (sound) -> {
				this.value = sound;
				this.onAttributeChange(this);
			}
		});
		this.addChild(button);
		// 删除按钮
		var delete = new CommonButton("UIAtlas:trash");
		this.addChild(delete);
		delete.addEventListener(MouseEvent.CLICK, (e) -> {
			// 删除音频
			this.value = null;
			this.onAttributeChange(this);
		});
	}

	override function set_value(value:Dynamic):Dynamic {
		if (value != null && value != "") {
			this.button.text = value;
		} else {
			this.button.text = "选择";
		}
		return super.set_value(value);
	}
}
